package com.newer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newer.domain.Apply;
import com.newer.dto.ApplyandDetailsDto;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

public interface ApplyMapper extends BaseMapper<Apply> {

    @Select("select a.*,u.realName from t_apply a inner join t_user u on a.userId=u.userId where applyDate like CONCAT('%',#{applyDate},'%')")
    @Results({
            @Result(column = "applyId",property = "applyid"),
            @Result(column = "userId",property = "userid"),
            @Result(column = "planId",property = "planid"),
            @Result(column = "sumCount",property = "sumcount"),
            @Result(column = "sumPrice",property = "sumprice"),
            @Result(column = "approver",property = "approver"),
            @Result(column = "applyDate",property = "applydate"),
            @Result(column = "applyState",property = "applystate"),
            @Result(column = "realName",property = "user.realname"),
    })
    Page<Apply> selectApply(Page page,String applyDate);


    //查询状态为审核成功的采购申请
    @Select(" select a.*,u.realName,ad.*,m.materialName,m.imgName,m.unit from t_apply a inner join t_user u on a.userId=u.userId inner join t_appLy_Details ad on a.applyId=ad.applyId inner join t_material m  on ad.materialId=m.materialId where applyState='申请成功' and a.applyId like CONCAT('%',#{applyid},'%')")
    @Results({
            @Result(column = "applyId",property = "applyid"),
            @Result(column = "userId",property = "userid"),
            @Result(column = "planId",property = "planid"),
            @Result(column = "sumCount",property = "sumcount"),
            @Result(column = "sumPrice",property = "sumprice"),
            @Result(column = "approver",property = "approver"),
            @Result(column = "applyDate",property = "applydate"),
            @Result(column = "applyState",property = "applystate"),
            @Result(column = "realName",property = "realname"),
            @Result(column = "appLyDetailsId",property = "applydetailsid"),
            @Result(column = "count",property = "count"),
            @Result(column = "price",property = "price"),
            @Result(column = "materialName",property = "materialname"),
            @Result(column = "imgName",property = "imgname"),
            @Result(column = "unit",property = "unit"),
    })
    Page<ApplyandDetailsDto> seleceApplyandDetails(Page page,String applyid);

}